package com.example.matetest.slice.login;

import com.example.matetest.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.components.TextField;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class LoginAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private static final String TAG = LoginAbilitySlice.class.getSimpleName();
    private static final HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, 0x00001, TAG);

    private TextField loginName;
    private TextField loginPwd;
    private Text forgetPassword;
    private Button login;
    private Button register;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_login);

        loginName = (TextField) findComponentById(ResourceTable.Id_tf_login_phone);
        loginPwd = (TextField) findComponentById(ResourceTable.Id_tf_login_password);
        forgetPassword = (Text) findComponentById(ResourceTable.Id_tv_forget_password);
        forgetPassword.setClickedListener(this);
        login = (Button) findComponentById(ResourceTable.Id_btn_login);
        login.setClickedListener(this);
        register = (Button) findComponentById(ResourceTable.Id_btn_register);
        register.setClickedListener(this);

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }


    @Override
    public void onClick(Component component) {
        if (component == forgetPassword) {
            present(new ForgetPwdAbilitySlice(),new Intent());
        } else if (component == login) {
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName("com.example.matetest")
                    .withAbilityName("com.example.matetest.HomeAbility")
                    .build();
            intent.setOperation(operation);
            startAbility(intent);
        } else if (component == register) {
            present(new RegisterAbilitySlice(),new Intent());

        }
    }

}
